#include <stdio.h>
#include <stdlib.h>
#include "types.h"
#include "array.h"
#include "stack.h"


int main(int a, char** b) {
	printf("it is working kind of\n");

	FILE *myfile = fopen("in.txt", "r");
	// make sure it's valid..
	if (!myfile) {
		printf("I can't open that file!!!!\n");
		return -1;
	}

	printf("creating a stack..\n");
	stack_c myStack;
	stackInit(&myStack);

	int status = (myStack.push)(&myStack, 100);


	command_c* myArray = NULL; // does some cool thing
	int length         = 5;    // does another cool thing

	initArray(&myArray, &length);
	increaseArray(&myArray, &length);
	/// NOTE: Currently the array does NOT automatically grow even though it can. so like. make sure its big enough mate just repeat that function before a few times if ur gettin errors


	parse_to_array(&myArray, &length, &myfile);

	printf("elem1: %d\n", myArray[0].push_d.num);

	int lineNumber = 0;  // we start at line 0 and start executing the commands..
	int running    = 1;
	do { // starting to run the actual script...
		switch(myArray[lineNumber].type) {
			case NO_OP:
				break;

			case PUSH:
				printf("will push here\n");
				break;

			case POP:
				printf("will pop here\n");
				break;

			case ADD:
				printf("will add here\n");
				break;

			case IFEQ:
				printf("will ifeq here\n");
				break;

			case JUMP:
				printf("jumped\n");
				lineNumber = myArray[lineNumber].jump_d.address - 1;
				break;

			case PRINT:
				printf("will print here\n");
				break;

			case DUP:
				printf("will dup here\n");
				break;

			case END:
				printf("will end here\n");
				running = 0;
				break;

		}
		lineNumber ++;
	} while (running == 1);

	freeArray(&myArray);
}
